package main.social.dao;

import java.io.Serializable;
import java.util.List;

/**
 * A minimal generic dao interface.
 *
 * @param <T> the model class
 * @param <PK> the model class primary key type
 */
public interface GenericDao<T, PK extends Serializable> {

	/**
	 * Get a persistent entity by id
	 * @param id the id of the entity
	 * @return the entity instance or null if not found
	 */
	public T get(PK id);

	/**
	 * Get a persistent entity by id.  Assumes the id is valid.
	 * @param id the id of the entity
	 * @return the entity instance
	 */
	public T load(PK id);

	/**
	 * Get a count of entities
	 * @return the number of entities
	 */
	public long getCount();

	/**
	 * Get all persistent instances
	 * @return the list of entities
	 */
	public List<T> findAll();

	/**
	 * Delete a persistent entity
	 * @param entity the entity
	 */
	public void delete(T entity);

	/**
	 * Flush the session
	 */
	public void flush();

	/**
	 * Merge an entity with its persistent version
	 * @param entity the entity to merge
	 * @return the updated entity
	 */
	public T merge(T entity);

	/**
	 * Refresh an entity
	 * @param entity the entity
	 */
	public void refresh(T entity);

	/**
	 * Save an entity
	 * @param entity the entity
	 */
	public void save(T entity);

	/**
	 * Save or update an entity
	 * @param entity the entity
	 */
	public void saveOrUpdate(T entity);

	/**
	 * Update an entity
	 * @param entity the entity
	 */
	public void update(T entity);

}
